package com.zxy.main;

import java.sql.SQLException;

import com.zxy.business.Ope_DB_Cent;
import com.zxy.common.Com_Fun;
import com.zxy.common.Db_Common_InterFace;
import com.zxy.common.PooledConnection_InterFace;
import com.zxy.model.T_PROC_NAME;

public class Data_Deal
{
	public void DataIns(String strSql)
	{
		// 调用存储过程 案例
		Db_Common_InterFace dbc = null;
		PooledConnection_InterFace pi = null;
		java.sql.ResultSet rs = null;
		StringBuilder sqlException = null;
		try
		{
			Ope_DB_Cent odc = new Ope_DB_Cent();
			Object dbcobject = odc.Get_Db_Common(1);
			dbc = (Db_Common_InterFace) (odc.Obj_To_Db_Common(dbcobject));
			String[] Parameters =
			{ "1", "1", "1" };
			String[] ParamTypes =
			{ "STRING", "STRING", "STRING" };
			String[] ParamOutName = new String[0];
			String[] ParamOutType = new String[0];
			T_PROC_NAME tpn = new T_PROC_NAME();
			tpn.INF_TYPE = "2";
			tpn.INF_EN_SQL = "select 1 from xxx where xx=? and xx = ? and xx = ?";
			rs = dbc.Common_Sql_Proc("xxxxxx",Parameters,ParamTypes,ParamOutName,ParamOutType,tpn);
			boolean bIns = true;
			while(rs.next())
			{
				bIns = false;
				break;
			}
			if(bIns)
			{
				tpn.INF_EN_SQL = "insert into xx(xx,xx,xx) " + " values(?,?,?)";
				// 带参数
				rs = dbc.Common_Sql_Proc("xxxxxx",Parameters,ParamTypes,ParamOutName,ParamOutType,tpn);
			}
			
			//或者直接执行sql查询语句
			dbc.Common_Sql(new StringBuilder("select xx from xx"));
			//或者直接执行sql操作语句
			dbc.Common_Sql(new StringBuilder("delete from xx where MAIN_ID = '1'"));
			
			// 执行获取sql异常信息
			sqlException = dbc.getSqlException();
			//这句一定要加
			pi = (PooledConnection_InterFace) dbc.getConn_a();
		}
		catch(Exception e)
		{
			Com_Fun.debug_in(e,this.toString());
		}
		finally
		{
			try
			{
				if(!java.util.Objects.equals(rs,null))
				{
					rs.getStatement().close();
					rs.close();
				}
				if(!java.util.Objects.equals(dbc,null) && !pi.isB_nocursor())
				{
					if(!java.util.Objects.equals(pi,null)
							&& !java.util.Objects.equals(pi.getCalls(),null))
						pi.getCalls().close();
				}else if(!java.util.Objects.equals(dbc,null))
				{
					pi.returnConnection();
				}
			}
			catch(SQLException e)
			{
				Com_Fun.debug_in(e,this.toString(),"db close");
			}
		}
	}
}